package com.jx.mlxg.controller;

<<<<<<< HEAD
import com.jx.mlxg.entity.Users;
import com.jx.mlxg.service.UsersService;
import com.jx.mlxg.service.impl.MaterialRequestServiceImpl;
import com.jx.mlxg.service.impl.UsersServiceImpl;
import com.jx.mlxg.utils.JwtUtil;
import com.jx.mlxg.utils.ResponseResult;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
* 登录相关
* */
@Slf4j
@RestController
@RequestMapping("/user")
=======
import com.jx.mlxg.entity.MaterialRequest;
import com.jx.mlxg.service.impl.MaterialRequestServiceImpl;
import com.jx.mlxg.utils.PageResponse;
import com.jx.mlxg.utils.PageSearchRequest;
import com.jx.mlxg.utils.ResponseResult;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
>>>>>>> eb72a42842a7e02f996c4f2d21dc4051aa14ecf1
public class LoginController {
    @Resource
    MaterialRequestServiceImpl materialRequestServiceImpl;

<<<<<<< HEAD
    @Autowired
    private UsersService usersService;

    /**
    * login登录接口
    * */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody Map<String, String> requestParams) throws WxErrorException {
        log.info("login接口");

        String code = requestParams.get("code");
        String encryptedData = requestParams.get("encryptedData");
        String iv = requestParams.get("iv");
        String phoneCode = requestParams.get("phoneCode");

        // 参数校验
        if (code == null) {
            throw new IllegalArgumentException("Missing required parameters/user/login");
        }

        Map<String, Object> userInfoAndOrderStatistics = usersService.authWechat(code,phoneCode);
        return ResponseResult.success(userInfoAndOrderStatistics);

=======
    @RequestMapping("/login12")
    public ResponseResult<PageResponse<MaterialRequest>> login(PageSearchRequest request) {
        PageResponse<MaterialRequest> materialRequestMapper = materialRequestServiceImpl.getMaterialRequestMapper(request);
        return ResponseResult.success(materialRequestMapper);
>>>>>>> eb72a42842a7e02f996c4f2d21dc4051aa14ecf1
    }

    @RequestMapping
    @PreAuthorize("hasAuthority('USER')")
    public String getProtectedResources() {
        String username = SecurityContextHolder.getContext().getAuthentication().getName();

        return "Hello, "+ username+"!受保护页面";
    }
}
